package com.PVZ.model.interfaces;

import com.PVZ.event.Event;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by @Author: kabuda on @Date: 2021/5/20 11:33
 */
@Data
public class EventSource {
    private List<EventListener> events = new ArrayList<>();
    public void bindListener(EventListener listener){
        this.events.add(listener);
    };

    /**
     * 通知监听器处理事件
     * @param event 需处理的事件
     */
    public void notifyListener(Event event){
        for (EventListener listener : events) {
            listener.eventHandler(event);
        }
    };
}
